package com.test.pattern.builder.demo2;

/**
 * 建造者模式构建对象,使用lombok的@Builder注解也可以实现该效果
 * @ClassName: Phone
 * @description: 手机类
 * @author: Mr du
 * @create: 2024-02-17 21:12
 */
public class Phone {

    /**
     * 处理器
     */
    private String cpu;

    /**
     * 屏幕
     */
    private String screen;

    /**
     * 内存
     */
    private String memory;

    /**
     * 主板
     */
    private String mainboard;

    private Phone(Builder builder){
        this.cpu = builder.cpu;
        this.screen = builder.screen;
        this.memory = builder.memory;
        this.mainboard = builder.mainboard;
    }

    public static final class Builder{
        /**
         * 处理器
         */
        private String cpu;

        /**
         * 屏幕
         */
        private String screen;

        /**
         * 内存
         */
        private String memory;

        /**
         * 主板
         */
        private String mainboard;


        public Builder() {}

        public Builder cpu(String cpu){
            this.cpu = cpu;
            return this;
        }

        public Builder screen(String screen) {
            this.screen = screen;
            return this;
        }
        public Builder memory(String memory) {
            this.memory = memory;
            return this;
        }
        public Builder mainboard(String mainboard) {
            this.mainboard = mainboard;
            return this;
        }

        public Phone build(){
            return new Phone(this);
        }
    }

    @Override
    public String toString() {
        return "Phone{" +
                "cpu='" + cpu + '\'' +
                ", screen='" + screen + '\'' +
                ", memory='" + memory + '\'' +
                ", mainboard='" + mainboard + '\'' +
                '}';
    }
}
